//
//  stats_client_processor.hpp
// ~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2013-2014 Razvan Coca (razvan dot coca at  gmail dot com)
//

#ifndef STATS_CLIENT_PROCESSOR_HPP
#define STATS_CLIENT_PROCESSOR_HPP
#include <boost/logic/tribool_fwd.hpp>
#include <boost/asio.hpp>
#include "stats_client/stats.pb.h"
#include "components/defs/util_types.hpp"
#include "logging/logging.hpp"
namespace components{
namespace protocol{

class stats_client_processor
{

public:
    enum states{start, replies};

private:
    std::vector<stats_message_t> data_;
    std::string cluster_;
    std::string node_;
    void update_source(stats_message_t& msg);
    void init_trans(stats_message_t& msg);
    void update_trans(stats_message_t& msg);
    enum states current_state;
    u_int32_t trans_id_;
    u_int32_t seq_no_;
public:
    stats_client_processor(const std::string &cluster, const std::string &node);
    std::vector<stats_message_t> data(){return data_;}
    boost::logic::tribool process_request_set(stats_message_t& msg,udp_endpoint_t& peer,boost::system::error_code const &ec);
    boost::logic::tribool process_request_get(stats_message_t& msg,udp_endpoint_t& peer,boost::system::error_code const &ec);
    boost::logic::tribool process_reply(stats_message_t& msg,udp_endpoint_t& peer,boost::system::error_code const &ec);
    boost::logic::tribool process_end(stats_message_t& msg,udp_endpoint_t& peer,boost::system::error_code const &ec);
    boost::logic::tribool process_timeout(stats_message_t& msg,udp_endpoint_t& peer,boost::system::error_code const &ec);

};
}// end namespace protocol
}// end namespace components
#endif // STATS_CLIENT_PROCESSOR_HPP
